import cv2 as cv
import numpy as np


def main():
    img_rgb = cv.imread('../data/mario.png')
    img_org = img_rgb.copy()
    img_gray = cv.cvtColor(img_rgb, cv.COLOR_BGR2GRAY)
    template = cv.imread('../data/mario_coin.png', 0)
    w, h = template.shape[::-1]
    res = cv.matchTemplate(img_gray, template, cv.TM_CCOEFF_NORMED)
    loc = np.where(res >= 0.9)
    for pt in zip(*loc[::-1]):
        cv.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 1)
    cv.imshow("res", res)
    cv.imshow("img_org", img_org)
    cv.imshow("img_rgb", img_rgb)
    cv.waitKey(0)
    cv.destroyAllWindows()


if __name__ == "__main__":
    main()
